package com.xiaohu.transfrom;

import com.xiaohu.bean.WaterSensor;
import com.xiaohu.implclass.MyMapFunction1;
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;




public class MapDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);


        DataStreamSource<WaterSensor> source = env.fromElements(
                new WaterSensor("s1", 1L, 1),
                new WaterSensor("s2", 2L, 2),
                new WaterSensor("s3", 3L, 3)
        );

        // TODO: 使用匿名内部类实现
//        SingleOutputStreamOperator<String> map = source.map(new MapFunction<WaterSensor, String>() {
//            @Override
//            public String map(WaterSensor value) throws Exception {
//                return value.getId();
//            }
//        });

        // TODO: 使用lambda表达式实现
//        SingleOutputStreamOperator<String> map = source.map(WaterSensor::getId);

        // TODO: 如果多个作业具有相同的处理逻辑，可以自定义一个实现类
        SingleOutputStreamOperator<String> map = source.map(new MyMapFunction1());

        map.print();


        env.execute();
    }
}
